import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { SWrestleBattles } from "../../../../Message/Public/SWrestleBattles";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { AIManager } from "../../scene/ai/AIManager";
import { ENpcEffect } from "../../../../Message/Public/ENpcEffect";
import { WrestleDateWindow } from "./WrestleDateWindow";
import { WrestleWeekWindom } from "./WrestleWeekWindom";
import { WrestleMonthWindow } from "./WrestleMonthWindow";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { TitleItem } from "../common/item/TitleItem";
import { ObjTeamCreate } from "../common/ObjTeamCreate";
import { TilePanel } from "../equipment/TilePanel";
import { WrestleBattleCellRenderer } from "./cellRendener/WrestleBattleCellRenderer";
import { MyWrestleInfo } from "./wrestleData/MyWrestleInfo";
import { SWrestleAccount } from "../../../../Message/Public/SWrestleAccount";
import { DateParser } from "../../../common/tools/DateParser";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class WrestleMainPanel
    
    export  class WrestleMainPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._glowYellow = new Object /* flash.filters.GlowFilter */(16776960, 1, 3, 3, 5);
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this.createLeftPart();
            this.createRightPart();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            this.updateMyArenaMoney(Cache.instance.role.money.arena);
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleGetMyWrestleInfo));
            Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleGetWrestleBattles));
            if (Cache.instance.wrestle.account) 
            {
                this.updateAccount(Cache.instance.wrestle.account);
            }
            return;
        }

        /* internal  */createLeftPart(): void
        {
            var loc1=null;
            var loc2=null;
            loc1 = new Object /* flash.display.Sprite */();
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createBg(0, 0, 193, 483, loc1);
            loc2 = GlobalClass.getBitmap(ImagesConst.fairylandPattern);
            loc2.x = 2;
            loc2.y = 2;
            loc1.addChild(loc2);
            ObjCreate.createTextField(Language.getString(42302), 12, 5, 150, 20, loc1, GlobalStyle.textFormat6);
            this._tfName = this.createItemValue(Language.getString(42214), "0", 12, 35, 150, 20, loc1);
            this._tfScore = this.createItemValue(Language.getString(42215), "0", 12, 54, 90, 20, loc1);
            this._tfRank = this.createItemValue(Language.getString(42216), "0", 104, 54, 90, 20, loc1);
            this._tfTotal = this.createItemValue(Language.getString(42219), "0", 12, 74, 90, 20, loc1);
            this._tfRankCross = this.createItemValue(Language.getString(42303), "0", 104, 74, 90, 20, loc1);
            this._tfWin = this.createItemValue(Language.getString(42217), "0", 12, 94, 90, 20, loc1);
            this._tfLose = this.createItemValue(Language.getString(42218), "0", 104, 94, 90, 20, loc1);
            this._tfWinPer = this.createItemValue(Language.getString(42220), "100%", 12, 114, 90, 20, loc1);
            this._tfTotayMatchNum = ObjCreate.createTextField(Language.getString(42304), 12, 150, 190, 20, this);
            this._tfMatchNumNeed = ObjCreate.createTextField(Language.getString(42305), 12, 172, 190, 20, this);
            this._bgLong = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bgLong, 3, 228, -1, -1, loc1);
            LoaderHelp.addResCallBack(ResFileConst.areanCrossMain, this.onResCompl);
            this._btnJoin = ObjCreate.createGLoadedButton(ResFileConst.ArenaJoin, 46, 220, 102, 99, loc1);
            this._btnJoin.enabled = true;
            var loc3=ResouceConst.getScaleBitmap("SplitLine");
            ObjCreate.setObjAttri(loc3, 10, 348, 165, 2, loc1);
            loc1.addChild(loc3);
            this._btnJoin.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnJoin);
            this._spLeftBottom = new Object /* flash.display.Sprite */();
            this._spLeftBottom.x = 10;
            this._spLeftBottom.y = 365;
            loc1.addChild(this._spLeftBottom);
            this._tfMyArena = ObjCreate.createTextField(Language.getStringByParam(44494, 0), 12, 0, 120, 20, this._spLeftBottom, GlobalStyle.textFormat6);
            this._tfLastArena = ObjCreate.createTextField(Language.getStringByParam(44495, 0), 12, 20, 140, 20, this._spLeftBottom);
            this._btnExchangeArena = ObjCreate.createGButton(Language.getString(42306), 120, -5, 49, 28, this._spLeftBottom, "LinkButton");
            this._btnExchangeArena.addEventListener(flash.events.MouseEvent.CLICK, this.onClickExchangeArena);
            this._tfNextDayArena = ObjCreate.createTextField(Language.getString(42307), 12, 40, 110, 20, this._spLeftBottom, GlobalStyle.textFormat6);
            this._btnDayRule = ObjCreate.createGButton(Language.getString(42308), 115, 37, 70, 20, this._spLeftBottom, "LinkButton");
            this._tfNextWeekArena = ObjCreate.createTextField(Language.getString(42309), 12, 60, 110, 20, this._spLeftBottom, GlobalStyle.textFormat6);
            this._btnWeekRule = ObjCreate.createGButton(Language.getString(42310), 115, 57, 70, 20, this._spLeftBottom, "LinkButton");
            this._tfNextMonthArena = ObjCreate.createTextField(Language.getString(42311), 12, 80, 110, 20, this._spLeftBottom, GlobalStyle.textFormat6);
            this._btnMonthRule = ObjCreate.createGButton(Language.getString(42312), 115, 77, 70, 20, this._spLeftBottom, "LinkButton");
            this._btnExchangeArena.addEventListener(flash.events.MouseEvent.CLICK, this.onClickExchange);
            this._btnDayRule.addEventListener(flash.events.MouseEvent.CLICK, this.onClickDayRule);
            this._btnWeekRule.addEventListener(flash.events.MouseEvent.CLICK, this.onClickWeekRule);
            this._btnMonthRule.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMonthRule);
            return;
        }

        public updateBattles(arg1: SWrestleBattles): void
        {
            var loc1=arg1 && arg1.battles.length;
            this._battlePanel.visible = loc1;
            this._tfNoRecord.visible = !loc1;
            this._battlePanel.dataProvider = new DataProvider(arg1.battles);
            this._battlePanel.drawNow();
            return;
        }

        /* internal  */onClickExchange(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAutoPathAIControl(Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectAthleticsExchange));
            return;
        }

        /* internal  */onClickDayRule(arg1: Object /* flash.events.MouseEvent */): void
        {
            WrestleDateWindow.instance.show();
            return;
        }

        /* internal  */onClickWeekRule(arg1: Object /* flash.events.MouseEvent */): void
        {
            WrestleWeekWindom.instance.show();
            return;
        }

        /* internal  */onClickMonthRule(arg1: Object /* flash.events.MouseEvent */): void
        {
            WrestleMonthWindow.instance.show();
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._bgLong.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaCrossBg);
            return;
        }

        /* internal  */onClickExchangeArena(arg1: Object /* flash.events.MouseEvent */): void
        {
            return;
        }

        /* internal  */onClickRefresh(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleGetWrestleBattles));
            return;
        }

        /* internal  */createItemValue(arg1: string, arg2: string="", arg3: number=0, arg4: number=0, arg5: number=90, arg6: number=20, arg7: Object /* flash.display.DisplayObjectContainer */=null): Object /* flash.text.TextField */
        {
            var loc1=ObjCreate.createTextField("", arg3, arg4, arg5, arg6, arg7);
            this.updateItemValue(loc1, arg1, arg2);
            return loc1;
        }

        /* internal  */updateItemValue(arg1: Object /* flash.text.TextField */, arg2: string, arg3: string): void
        {
            arg1.htmlText = HTMLUtil.addColor(arg2, "#FFFFFF") + HTMLUtil.addColor(arg3, GlobalStyle.color1);
            return;
        }

        /* internal  */onBtnJoin(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=false;
            if (this._btnJoin.styleName != ResFileConst.ArenaJoin) 
            {
                loc1 = true;
            }
            else 
            {
                loc1 = false;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.WrestleJoin, loc1));
            return;
        }

        /* internal  */createRightPart(): void
        {
            var loc1=null;
            loc1 = new Object /* flash.display.Sprite */();
            loc1.x = 196;
            loc1.mouseEnabled = false;
            this.addChild(loc1);
            ObjCreate.createSpBannerAndBg(0, 0, 607, 449, "", loc1);
            var loc2=new Vector.<TitleItem>();
            loc2.push(new TitleItem(Language.getString(44436), 180));
            loc2.push(new TitleItem(Language.getString(44470), 60));
            loc2.push(new TitleItem("", 45));
            loc2.push(new TitleItem(Language.getString(44436), 180));
            loc2.push(new TitleItem(Language.getString(44470), 60));
            loc2.push(new TitleItem(Language.getString(44501), 80));
            var loc3=ObjTeamCreate.createTitles(loc2);
            ObjCreate.setObjAttri(loc3, 0, 7, -1, -1, loc1);
            this._tfNoRecord = ObjCreate.createTextField(Language.getString(44502), 240, 200, 200, 20, loc1, GlobalStyle.textFormat6);
            this._tfNoRecord.visible = true;
            this._battlePanel = new TilePanel();
            this._battlePanel.setSize(606, 420);
            this._battlePanel.rowHeight = 42;
            this._battlePanel.columnWidth = 606;
            this._battlePanel.setStyle("cellRenderer", WrestleBattleCellRenderer);
            this._battlePanel.x = 0;
            this._battlePanel.y = 30;
            this._battlePanel.visible = false;
            loc1.addChild(this._battlePanel);
            this._btnRefresh = ObjCreate.createGButton(Language.getString(44503), 275, 457, 60, 22, loc1);
            this._btnRefresh.addEventListener(flash.events.MouseEvent.CLICK, this.onClickRefresh);
            return;
        }

        public resetOpenState(arg1: Boolean): void
        {
            return;
        }

        public updateMyWrestleInfo(arg1: MyWrestleInfo): void
        {
            this.updateItemValue(this._tfName, Language.getString(42214), arg1.name);
            this.updateItemValue(this._tfScore, Language.getString(42215), arg1.mark.toString());
            var loc1=Language.getString(42231);
            var loc2=Language.getString(42231);
            if (arg1.rank != 0) 
            {
                loc1 = arg1.rank.toString();
            }
            if (arg1.rankCross != 0) 
            {
                loc2 = arg1.rankCross.toString();
            }
            this.updateItemValue(this._tfRankCross, Language.getString(42303), loc2);
            this.updateItemValue(this._tfRank, Language.getString(42216), loc1);
            this.updateItemValue(this._tfWin, Language.getString(42217), arg1.winNum.toString());
            this.updateItemValue(this._tfLose, Language.getString(42218), arg1.loseNum.toString());
            this.updateItemValue(this._tfTotal, Language.getString(42219), arg1.totleNum.toString());
            this.updateItemValue(this._tfWinPer, Language.getString(42220), arg1.winPer.toString() + "%");
            this._tfLastArena.text = Language.getStringByParam(42339, arg1.lastWrestleMoney.toString());
            ObjTeamCreate.setTextFieldKeyValue(this._tfTotayMatchNum, Language.getString(44491), arg1.todayNum.toString(), "", "#FFFFFF");
            var loc3=10 - arg1.dailyNum;
            var loc4=Language.getStringByParam(44492, arg1.dailyNum.toString());
            if (loc3 > 0) 
            {
                loc4 = loc4 + Language.getStringByParam(44591, loc3.toString());
            }
            this._tfMatchNumNeed.htmlText = loc4;
            return;
        }

        public updateAccount(arg1: SWrestleAccount): void
        {
            this._tfNextDayArena.text = Language.getString(42307) + DateParser.parse(arg1.dailyAccountDt, Language.getString(42314));
            this._tfNextWeekArena.text = Language.getString(42309) + DateParser.parse(arg1.weekAccountDt, Language.getString(42314));
            this._tfNextMonthArena.text = Language.getString(42311) + DateParser.parse(arg1.monthAccountDt, Language.getString(42314));
            return;
        }

        public updateMyArenaMoney(arg1: int): void
        {
            this._tfMyArena.text = Language.getStringByParam(42222, arg1.toString());
            return;
        }

        public updateSignUpState(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._btnJoin.styleName = ResFileConst.ArenaCancelJoin;
            }
            else 
            {
                this._btnJoin.styleName = ResFileConst.ArenaJoin;
            }
            return;
        }

        /* internal */ /* const */pageSize: int=10;

        /* internal */ /* var */_tfNextMonthArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnDayRule: GButton;

        /* internal */ /* var */_btnWeekRule: GButton;

        /* internal */ /* var */_tfWin: Object /* flash.text.TextField */;

        /* internal */ /* var */_battlePanel: TilePanel;

        /* internal */ /* var */_tfNoRecord: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnRefresh: GButton;

        /* internal */ /* var */_battleList: Array<any>;

        /* internal */ /* var */_tfName: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnMonthRule: GButton;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfLose: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTotal: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfTotalRank: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWinPer: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfRankCross: Object /* flash.text.TextField */;

        /* internal */ /* var */_glowYellow: Object /* flash.filters.GlowFilter */;

        /* internal */ /* var */_tfTotayMatchNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfMatchNumNeed: Object /* flash.text.TextField */;

        /* internal */ /* var */_bgLong: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnJoin: GLoadedButton;

        /* internal */ /* var */_tfLastArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_spLeftBottom: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfMyArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnExchangeArena: GButton;

        /* internal */ /* var */_tfNextDayArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNextWeekArena: Object /* flash.text.TextField */;

        /* internal */ /* var */_isInCd: Boolean=false;
    }
